package cn.heygod.sample.web;

import cn.heygod.airsql.Sql;
import cn.heygod.airsql.support.Page;
import cn.heygod.sample.entity.SysUser;
import cn.hutool.core.util.IdUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @className: UserController
 * @author: Simon
 * @description: TODO
 * @date: 2024/1/28 19:26
 * @version: 1.0
 */
@Controller
@RequestMapping("/api")
public class UserController {

    //@Autowired
    @RequestMapping("/user/find")
    @ResponseBody
    public Object findUser(){
        List list = Sql.select(SysUser.class)
                .likeRight(SysUser::getPhone,"155")
               // .ge(SysUser::getDeptId,6)
                .desc(SysUser::getUsername)
                .query();
        Page page = Sql.select(SysUser.class)
                .likeRight(SysUser::getPhone,"155")
                // .ge(SysUser::getDeptId,6)
                .desc(SysUser::getUsername)
                .limit(0,5)
                .queryPage();
        return page;
    }

    @RequestMapping("/user/insert")
    @ResponseBody
    public Object insertUser(){
       SysUser user = new SysUser();
       user.setUserId(IdUtil.getSnowflake().nextIdStr());
       user.setUsername("idea user");
       user.setPassword("aadf");
       Integer result = Sql.insert(SysUser.class).object(user).execute();
        return result;
    }

}
